﻿using AnlianCommon.Common.Domains.ProductionManagement;
using AnlianCommon.Common.DTO;
using AnlianCommon.Common.Infrastructure.IRepository;
using AnlianCommon.Enum;
using AutoMapper;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace SheepCommon.API.SheepCommands
{
    public class SheepEarBuglesQueryHandler : IRequestHandler<SheepEarBuglesQueryCommand, Result>
    {
        private readonly IBaseRepository<SheepArchives> _sheepArchivesRepository;

        public SheepEarBuglesQueryHandler(IBaseRepository<SheepArchives> sheepArchivesRepository)
        {
            _sheepArchivesRepository = sheepArchivesRepository;
        }
        /// <summary>
        /// 查询耳号 业务逻辑
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Result> Handle(SheepEarBuglesQueryCommand request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCode.Search };
            try
            {
                var sheepArchives = await (from a in await _sheepArchivesRepository.GetAll()
                                           select new SheepArchives()
                                           {
                                               RecordId = a.RecordId,
                                               RecordAuricle = a.RecordAuricle,
                                           }).ToListAsync();
                result.Data = sheepArchives;
            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }
    }
}
